package com.feri.findlife.service.impl;

import com.feri.findlife.dao.CirclePassDao;
import com.feri.findlife.dao.WorriedDao;
import com.feri.findlife.dto.WorriedSaveDto;
import com.feri.findlife.pojo.Worried;
import com.feri.findlife.service.intf.WorriedService;
import com.feri.findlife.vo.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @program: FindLife
 * @description:
 * @author: Feri(邢朋辉)
 * @create: 2020-12-22 11:21
 */
@Service
public class WorriedServiceImpl implements WorriedService {
    @Autowired
    private WorriedDao dao;
    @Autowired
    private CirclePassDao passDao;
    @Override
    public R save(WorriedSaveDto dto) {
        //校验-圈子和口令
        if(passDao.selectPass(dto.getCid(),dto.getPass())!=null){
            //存在 合法
            //保存内容
            Worried worried=new Worried(dto.getCid(),dto.getTitle(),dto.getContent(),dto.getTyp());
            //讲内容存储到数据库
            if(dao.save(worried)>0){
                return R.ok();
            }
        }
        return R.fail();
    }
    @Override
    public R all(int cid) {
        if(cid>0) {
            return R.ok(dao.selectByCid(cid));
        }else {
            return R.fail("非法的值");
        }
    }
}
